//
//  CTHomePageViewController.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/5.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTHomePageViewController.h"
#import "CTTabBarController.h"
#import "CTSubjectDetailViewController.h"
#import "CTTabBarController.h"
#import "CTCommentViewController.h"
#import "CTUserViewController.h"
#import "CTLoginViewController.h"
#import "APService.h"

//config
#import "CTHeader.h"

//view
#import "CTHomePageView.h"
//#import "CTPublishTypePickView.h"
#import "CTShareView.h"

//logic
#import "CTHomePageLogic.h"
#import "CTLogin.h"
#import "CTLogic.h"

//model
#import "CTHomePageItems.h"
#import "CTShareItem.h"
#import "CTLogicItems.h"
#import "CTUserItem.h"

//view
#import "CTActivitorView.h"

//function
#import "CTDebugManager.h"
#import "CTDeviceFunction.h"
#import "CTGenRequestData.h"
#import "CTDataGenerator.h"
#import "CTRemindView.h"
#import "CTAppLanguage.h"
#import "CTShare.h"
#import "CTRequestUtil.h"
#import "CTRemindView.h"
#import "CTMoreView.h"
#import "CTTextManager.h"
#import "CTActivitorView.h"
#import "CTReachability.h"
#import "CTImageProcessing.h"
#import "MobClick.h"

//tool
#import "UIImageView+MJWebCache.h"
#import "MJPhotoBrowser.h"
#import "MJPhoto.h"
#import "AFNetworkReachabilityManager.h"

static NSInteger homePageFlipNumber = 0;

typedef enum {
    ShareTypeSubject = 1,
    ShareTypeHotSpotsDetail
}ShareType;


typedef enum{
    ReportTypeReport = 1,
    ReportTypeDelete
}ReportType;


@interface CTHomePageViewController ()<CTHomePageViewDelegate,CTShareViewDelegate,CTMoreViewDelegate,UIAlertViewDelegate>
{
    CTHomePageView * homePageView;
    CTHomePageLogic * homePageLogic;
    
    CTHotSpotsItem * currentHotSpotsItem;
    CTHotSpotsDetailItem * currentHotSpotsDetailsItem;
    
    CTShareView * shareView;
    
    CTActivitorView * acView;
    
    ShareType shareType;
    ReportType reportType;
    
    CTLogic * logic;
    
    UIView * topView;
    CTActivitorView * activitorView;
    
    UIImage     *shareImage;
}
@end

@implementation CTHomePageViewController

- (void)dealloc
{
    [activitorView removeMoeMarkActivitorView];
    activitorView = nil;
    [topView removeFromSuperview];
    topView = nil;
    
    shareImage = nil;
    
    [homePageView removeFromSuperview];
    homePageView = nil;
    
    [shareView removeFromSuperview];
    shareView = nil;
    
    [acView removeFromSuperview];
    acView = nil;
    
    homePageLogic = nil;
    
    logic = nil;
  
    currentHotSpotsItem = nil;
    currentHotSpotsDetailsItem = nil;
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CTLoginSuccessNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CTExitSuccessNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_FOLLOWING_SUCCESS object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_CANCEL_FOLLOWING_SUCCESS object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_LIKE_SUCCESS object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_CANCEL_LIKE_SUCCESS object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_PUBLISH_COMMENT_SUCCESS object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_DELETE_COMMENT_SUCCESS object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_DELETE_PUBLISH_SUCCESS object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_JUMP_TO_GROUP object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_PUBLISH_SUCCESS object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_VISITOR_ERROR_REQUEST object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:CT_NOTI_CLEAR_CACHE object:nil];
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTHomePageViewController Is Removed!!!"];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [homePageView reloadData];

    //统计
    [MobClick beginLogPageView:@"CTHomePageViewController"];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    //统计
    [MobClick endLogPageView:@"CTHomePageViewController"];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        homePageLogic = [[CTHomePageLogic alloc] init];
        logic = [[CTLogic alloc] init];
        
        //注册登录&退出
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess:) name:CTLoginSuccessNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitSuccess:) name:CTExitSuccessNotification object:nil];
        
        //关注成功，从新刷新数据库数据
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(followPersonSuccess:) name:CT_NOTI_FOLLOWING_SUCCESS object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cancelFollowPersonSuccess:) name:CT_NOTI_CANCEL_FOLLOWING_SUCCESS object:nil];
        
        //点赞成功，从新刷新数据库数据
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(likePersonSuccess:) name:CT_NOTI_LIKE_SUCCESS object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cancelLikePersonSuccess:) name:CT_NOTI_CANCEL_LIKE_SUCCESS object:nil];
        
        //评论成功
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(publishCommentSuccessed:) name:CT_NOTI_PUBLISH_COMMENT_SUCCESS object:nil];
        
        //删除评论
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteCommentSuccessed:) name:CT_NOTI_DELETE_COMMENT_SUCCESS object:nil];
        
        //删除发布内容
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deletePublishSuccessed:) name:CT_NOTI_DELETE_PUBLISH_SUCCESS object:nil];
        
        //跳转相应话题
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jumpToGroup:) name:CT_NOTI_JUMP_TO_GROUP object:nil];
        
        //注册发布内容通知
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(publishSuccess:) name:CT_NOTI_PUBLISH_SUCCESS object:nil];
        
        //token验证失败从新请求登录
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(visitorReLogin:) name:CT_NOTI_VISITOR_ERROR_REQUEST object:nil];
        
        //清理缓存
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clearCacheSuccess:) name:CT_NOTI_CLEAR_CACHE object:nil];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = CT_HEADER_WHITE_COLOR;
    
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [self.view addSubview:topView];
    UIImageView * titleLogo = [[UIImageView alloc] initWithFrame:CGRectMake((CT_HEADER_SCREEN_WIDTH - 97)/2.0, 31,97, 19)];
    titleLogo.image = [UIImage imageNamed:@"logo"];
    [topView addSubview:titleLogo];
    
    UIView * topLineView = [[UIView alloc] initWithFrame:CGRectMake(0,63.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topLineView.backgroundColor = [UIColor colorWithRed:164/255.0 green:164/255.0 blue:164/255.0 alpha:1.0];
    [topView addSubview:topLineView];
    
    activitorView = [[CTActivitorView alloc] init];
    [activitorView showMoeMarkActivitorViewOn:self.view];
    
    [self checkNetworkState];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)creatHomePageViewDefault
{
    [activitorView removeMoeMarkActivitorView];
    activitorView = nil;
    [topView removeFromSuperview];
    topView = nil;
    
    if (homePageView == nil) {
        homePageView = [[CTHomePageView alloc] initWithType:CTHomePageViewTypeDefault];
        homePageView.delegate  = self;
        [self.view addSubview:homePageView];
    }else{
        [homePageView removeFromSuperview];
        homePageView = nil;
        homePageView.delegate = nil;
        
        homePageView = [[CTHomePageView alloc] initWithType:CTHomePageViewTypeDefault];
        homePageView.delegate  = self;
        [self.view addSubview:homePageView];
    }
}

-(void)creatHomePageViewNoData
{
    [activitorView removeMoeMarkActivitorView];
    activitorView = nil;
    [topView removeFromSuperview];
    topView = nil;
    
    if (homePageView == nil) {
        homePageView = [[CTHomePageView alloc] initWithType:CTHomePageViewTypeNoData];
        homePageView.delegate  = self;
        [self.view addSubview:homePageView];
    }else{
        [homePageView removeFromSuperview];
        homePageView = nil;
        homePageView.delegate = nil;
        
        homePageView = [[CTHomePageView alloc] initWithType:CTHomePageViewTypeNoData];
        homePageView.delegate  = self;
        [self.view addSubview:homePageView];
    }
}

#pragma mark - request -

-(void)visitorLogin
{
    
    if ([CTLogin isLoginState] == NO) {
        
        [CTLogin visitorLoginWithsSuccessCompletionHandler:^(CTVisitorLoginCompletionItem *item) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self sendHotSpotsRequest];
            });
            
        } failedHandler:^{
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self creatHomePageViewNoData];
            });
        }];
    }else{
        
        [self sendHotSpotsRequest];
    }
}


-(void)sendHotSpotsRequest
{
    [homePageLogic hotSpotsRequest:[CTGenRequestData genRequestHotSpotsItem] successCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [self creatHomePageViewDefault];
            
            NSArray * arr = [CTDataGenerator generateHotSpotsItems];
            homePageView.classficationArray = arr;
        });
    } failedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_RemindView_A" withValue:nil withTable:@"Language"]];
            
            //请求失败 从数据库拿数据 主题分类
            NSArray * arr = [CTDataGenerator generateHotSpotsItems];
            if (arr != nil || arr.count != 0)
            {
                [self creatHomePageViewDefault];
                
                homePageView.classficationArray = arr;
            }
            else
            {
                [self creatHomePageViewNoData];
            }
            
        });
    }];
}

-(void)sendHotSpotDetailRequest
{
    homePageFlipNumber = 1;
    
    [homePageLogic hotSpotsDetailRequest:[CTGenRequestData genRequestHotSpotsDetailItem:currentHotSpotsItem withFilpNumber:homePageFlipNumber] successCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            NSArray * arr = [CTDataGenerator generateHotSpotsDetailItems:currentHotSpotsItem];
            homePageView.hotSpotsDetailArray = arr;
            
            [homePageView refreshPullDownEnd];
        });
    } failedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_RemindView_A" withValue:nil withTable:@"Language"]];
            
            [homePageView refreshPullDownEnd];
            
            NSArray * arr = [CTDataGenerator generateHotSpotsDetailItems:currentHotSpotsItem];
            if (arr != nil || arr.count != 0) {
                homePageView.hotSpotsDetailArray = arr;
            }else{
                
            }
            
        });
    }];
}

-(void)sendHotSpotDetailFilpRequest
{
    homePageFlipNumber ++;
    
    [homePageLogic hotSpotsDetailFlipRequest:[CTGenRequestData genRequestHotSpotsDetailItem:currentHotSpotsItem withFilpNumber:homePageFlipNumber] successCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            NSArray * arr = [CTDataGenerator generateHotSpotsDetailItems:currentHotSpotsItem];
            homePageView.hotSpotsDetailArray = arr;
            
            [homePageView refreshPullDownEnd];
        });
    } failedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_RemindView_A" withValue:nil withTable:@"Language"]];
            
            [homePageView refreshPullDownEnd];
            
            NSArray * arr = [CTDataGenerator generateHotSpotsDetailItems:currentHotSpotsItem];
            if (arr != nil || arr.count != 0) {
                homePageView.hotSpotsDetailArray = arr;
            }else{
                
            }
        });
    }];
}

-(void)sendSubjectRequest
{
    [homePageLogic subjectRequest:[CTGenRequestData genRequestSubjectItem:currentHotSpotsItem] successCompletionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTSubjectItem * itm = [CTDataGenerator generateSubjectItems:currentHotSpotsItem];
            homePageView.subjectItem = itm;
            
            [homePageView refreshPullDownEnd];
        });
        
    } failedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_RemindView_A" withValue:nil withTable:@"Language"]];
            
            [homePageView refreshPullDownEnd];
            
            CTSubjectItem * subjItem = [CTDataGenerator generateSubjectItems:currentHotSpotsItem];
            if (subjItem != nil) {
                homePageView.subjectItem = subjItem;
            }else{
                
            }
        });
    }];
}

#pragma mark - check net work state -
-(BOOL)checkNetworkState
{
    __block NSString * descri;
    __block CTRemindView * remindView;
    __block BOOL isCheck = YES;

    
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (status == AFNetworkReachabilityStatusNotReachable) {
                descri = [CTAppLanguage localizedStringForKey:@"remindView_login_networkReachable" withValue:nil withTable:@"Language"];
                remindView = [[CTRemindView alloc] init];
                [remindView showRemindViewOn:self.view withRemindWord:descri];
                
                isCheck = NO;
                
                [self creatHomePageViewNoData];
                
            }else if (status == AFNetworkReachabilityStatusUnknown){
                descri = [CTAppLanguage localizedStringForKey:@"remindView_login_networkUnknow" withValue:nil withTable:@"Language"];
                remindView = [[CTRemindView alloc] init];
                [remindView showRemindViewOn:self.view withRemindWord:descri];
                
                isCheck = NO;
                
                [self creatHomePageViewNoData];
                
            }
            else{
                [self visitorLogin];
            }
        });
        
    }];

    return isCheck;
}

#pragma mark - homePageView delegate -

-(void)classificationAction:(CTHomePageView *)view
                   withItem:(CTHotSpotsItem *)itm;
{
    currentHotSpotsItem = itm;
    
    NSArray * arr = [CTDataGenerator generateHotSpotsDetailItems:currentHotSpotsItem];
    if (arr != nil || arr.count != 0) {
        homePageView.hotSpotsDetailArray = arr;
    }else{
         [homePageView refresh];
    }
    
    CTSubjectItem * subjItem = [CTDataGenerator generateSubjectItems:currentHotSpotsItem];
    if (subjItem != nil) {
        homePageView.subjectItem = subjItem;
    }else{
         [homePageView refresh];
    }
}

-(void)refreshPullDown:(CTHomePageView *)view
{
    [self sendHotSpotDetailRequest];
    [self sendSubjectRequest];
    
}
-(void)refreshPullUp:(CTHomePageView *)view
{
    [self sendHotSpotDetailFilpRequest];
}

//主题代理
-(void)checkAction:(CTHomePageView *)view
{
    CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
    [tabbarVC hideTabbarWithAnimate:YES];
    
    CTSubjectDetailViewController * subjectDetailVC = [[CTSubjectDetailViewController alloc] init];
    subjectDetailVC.hotSpotsItem = currentHotSpotsItem;
    [self.navigationController pushViewController:subjectDetailVC animated:YES];
}
-(void)shareAction:(CTHomePageView *)view
{
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        shareType = ShareTypeSubject;
        
        //share view
        shareView = [[CTShareView alloc] init];
        shareView.delegate = self;
        [shareView showShareViewOn:self.view.window withShareViewType:CTShareViewTypeDefault];
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}

-(void)reloadViewAction:(CTHomePageView *)view
{
    [homePageView removeFromSuperview];
    homePageView = nil;
    homePageView.delegate = nil;
    
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [self.view addSubview:topView];
    UIImageView * titleLogo = [[UIImageView alloc] initWithFrame:CGRectMake((CT_HEADER_SCREEN_WIDTH - 97)/2.0, 31,97, 19)];
    titleLogo.image = [UIImage imageNamed:@"logo"];
    [topView addSubview:titleLogo];
    
    UIView * topLineView = [[UIView alloc] initWithFrame:CGRectMake(0,63.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topLineView.backgroundColor = [UIColor colorWithRed:164/255.0 green:164/255.0 blue:164/255.0 alpha:1.0];
    [topView addSubview:topLineView];
    
    activitorView = [[CTActivitorView alloc] init];
    [activitorView showMoeMarkActivitorViewOn:self.view];
    
     [self checkNetworkState];
}

/**
 *@brief 点击评论总数
 */
- (void)commentCountAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item
{
   
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        
        CTCommentViewController * commentVC = [[CTCommentViewController alloc] init];
        commentVC.followListItem = item.hotSpotsDetailItem;
        commentVC.levelType = CTCommentViewControllerLevelsFirst;
        [self.navigationController pushViewController:commentVC animated:YES];
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击评论第一条
 */
- (void)commentHitFirstLabelAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item
{
   
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        
        CTCommentViewController * commentVC = [[CTCommentViewController alloc] init];
        commentVC.followListItem = item.hotSpotsDetailItem;
        commentVC.levelType = CTCommentViewControllerLevelsFirst;
        [self.navigationController pushViewController:commentVC animated:YES];
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击评论第二条
 */
- (void)commentHitSecondLabelAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item
{
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        
        CTCommentViewController * commentVC = [[CTCommentViewController alloc] init];
        commentVC.followListItem = item.hotSpotsDetailItem;
        commentVC.levelType = CTCommentViewControllerLevelsFirst;
        [self.navigationController pushViewController:commentVC animated:YES];
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击评论第一条头像
 */
- (void)commentHitFirstHeadAction:(CTHomePageView *)view withItem:(CTComment *)item
{
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        CTUserViewController * userVC = [[CTUserViewController alloc] init];
        userVC.pushType = CTUserViewControllerPushFromTypeOther;
        userVC.levelType = CTUserViewControllerLevelFirst;
        userVC.userUid = item.user.uid;
        [self.navigationController pushViewController:userVC animated:YES];
        
        
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击评论第二条头像
 */
- (void)commentHitSecondHeadAction:(CTHomePageView *)view withItem:(CTComment *)item
{
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        CTUserViewController * userVC = [[CTUserViewController alloc] init];
        userVC.pushType = CTUserViewControllerPushFromTypeOther;
        userVC.levelType = CTUserViewControllerLevelFirst;
        userVC.userUid = item.user.uid;
        [self.navigationController pushViewController:userVC animated:YES];
        
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击头像
 */
- (void)hitHeadAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item
{
    
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        CTUserViewController * userVC = [[CTUserViewController alloc] init];
        userVC.pushType = CTUserViewControllerPushFromTypeOther;
        userVC.levelType = CTUserViewControllerLevelFirst;
        userVC.userUid = item.hotSpotsDetailItem.user.uid;
        [self.navigationController pushViewController:userVC animated:YES];
        
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击大图
 */
- (void)hitPicImageBtnAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item withImageView:(UIImageView *)imageView
{
    
    if ([[CTTextManager shareInstance] isBlankString:item.hotSpotsDetailItem.pic_url]) return;
    
    NSMutableArray * photos = [NSMutableArray arrayWithObjects:0, nil];
    MJPhoto *photo = [[MJPhoto alloc] init];
    photo.image = [CTRequestUtil requestImageWithUrl:item.hotSpotsDetailItem.pic_url]; // 图片路径
    photo.srcImageView = imageView;
    [photos addObject:photo];

//    if (photo.image == nil) return;
    // 2.显示相册
    MJPhotoBrowser *browser = [[MJPhotoBrowser alloc] init];
    browser.photos = photos; // 设置所有的图片
    [browser show];
    photos = nil;
    

}
/**
 *@brief 点赞
 */
- (void)hitFavourBtnAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item withBool:(BOOL) favBool
{
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        if (favBool == YES) {
            [logic likePersonRequest:[CTGenRequestData genRequestLikePseronItem:item.hotSpotsDetailItem.scheme_id] successCompletionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [CTDebugManager showDebugLogInfo:@"点赞成功！"];
                 //   [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_LIKE_SUCCESS object:nil];
                });
            } failedHandler:^{
                [CTDebugManager showErrorLogInfo:@"点赞失败！"];
            }];
        }else{
            [logic cancelLikePersonRequest:[CTGenRequestData genRequestCancelLikePseronItem:item.hotSpotsDetailItem.scheme_id] successCompletionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [CTDebugManager showDebugLogInfo:@"取消点赞成功！"];
                  //  [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_CANCEL_LIKE_SUCCESS object:nil];
                });
            } failedHandler:^{
                [CTDebugManager showErrorLogInfo:@"取消点赞失败！"];
            }];
        }
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击评论按钮
 */
- (void)hitCommentBtnaction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item
{
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        
        CTCommentViewController * commentVC = [[CTCommentViewController alloc] init];
        commentVC.followListItem = item.hotSpotsDetailItem;
        commentVC.levelType = CTCommentViewControllerLevelsFirst;
        [self.navigationController pushViewController:commentVC animated:YES];
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击分享按钮
 */
- (void)hitShareBtnAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item withImage:(UIImage *)shareImg
{
    shareImage = shareImg;
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        shareType = ShareTypeHotSpotsDetail;
        currentHotSpotsDetailsItem = item;
        
        //share view
        shareView = [[CTShareView alloc] init];
        shareView.delegate = self;
        [shareView showShareViewOn:self.view.window withShareViewType:CTShareViewTypeDefault];
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击更多按钮
 */
- (void)hitMoreBtnAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item
{
    currentHotSpotsDetailsItem = item;
    
    if ([CTLogin isUserLoginState] == YES) {
         //已登录
        CTUserItem * userItem = [CTUser userInfo];
        if ([item.hotSpotsDetailItem.user.uid isEqualToString:userItem.uid]) {
            CTMoreView * moreView = [[CTMoreView alloc] init];
            moreView.delegate = self;
            [moreView showMoreViewOn:self.view.window withMoreViewType:CTMoreViewTypeDefault];
        }else{
            CTMoreView * moreView = [[CTMoreView alloc] init];
            moreView.delegate = self;
            [moreView showMoreViewOn:self.view.window withMoreViewType:CTMoreViewTypeReport];
        }
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
    
}
/**
 *@brief 点击点赞的人的头像
 */
- (void)hitFavBtnHeadAction:(CTHomePageView *)view withItem:(CTListDetailUser *)item
{

    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        CTTabBarController * tabbarVC = (CTTabBarController *)self.navigationController.tabBarController;
        [tabbarVC hideTabbarWithAnimate:YES];
        CTUserViewController * userVC = [[CTUserViewController alloc] init];
        userVC.pushType = CTUserViewControllerPushFromTypeOther;
        userVC.levelType = CTUserViewControllerLevelFirst;
        userVC.userUid = item.uid;
        [self.navigationController pushViewController:userVC animated:YES];
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}
/**
 *@brief 点击关注按钮
 */
- (void)hitAttentionBtnAction:(CTHomePageView *)view withItem:(CTHotSpotsDetailItem *)item withBool:(BOOL)attenBool
{
    
    if ([CTLogin isUserLoginState] == YES) {
        //已登录
        if (attenBool == YES) {
            [logic followPersonRequest:[CTGenRequestData genRequestFollowPseronItem:item.hotSpotsDetailItem.user.uid] successCompletionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [CTDebugManager showDebugLogInfo:@"关注成功！"];
                  //  [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_FOLLOWING_SUCCESS object:nil];
                });
            } failedHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [CTDebugManager showErrorLogInfo:@"关注失败！"];
                });
            }];
        }else{
            [logic cancelFollowPersonRequest:[CTGenRequestData genRequestCancelFollowPseronItem:item.hotSpotsDetailItem.user.uid] successCompletionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [CTDebugManager showDebugLogInfo:@"取消关注成功！"];
                  //  [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_CANCEL_FOLLOWING_SUCCESS object:nil];
                });
            } failedHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    [CTDebugManager showErrorLogInfo:@"取消关注失败！"];
                });
            }];
        }
    }else{
        //未登录
        CTLoginViewController * loginVC = [[CTLoginViewController alloc] init];
        UINavigationController * loginNav = [[UINavigationController alloc] initWithRootViewController:loginVC];
        loginNav.navigationBarHidden = YES;
        
        [self presentViewController:loginNav animated:YES completion:^{
            
        }];
    }
}


/**
 *@brief 点击话题
 */
- (void)hitTopicBtnAction:(CTHomePageView *)view withItem:(CTTopic *)item
{
    [homePageView selectCurretGroup:item];
    [homePageView refresh];
}












#pragma mark - share view delegate -

//试图移除
-(void)viewDidRemoved:(CTShareView *)view
{
    shareView = nil;
    shareView.delegate = nil;
}
//分享到微信朋友圈
- (void)shareViewShareToWechatFriends:(CTShareView *) view withImage:(UIImage *)image
{
    CTShareItem * shareItem;
    if (shareType == ShareTypeSubject) {
        CTSubjectItem * itm = [CTDataGenerator generateSubjectItems:currentHotSpotsItem];
        
        shareItem = [[CTShareItem alloc] init];
        shareItem.content = itm.describe;
        shareItem.defaultContent = itm.describe;
        shareItem.img = [UIImage imageNamed:@"60x3"];
        shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_topic_describe" withValue:nil withTable:@"Language"];;
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = itm.share_url;
        
        
    }
    else
    {
        shareItem = [[CTShareItem alloc] init];
        shareItem.img = shareImage;
        shareItem.content = currentHotSpotsDetailsItem.hotSpotsDetailItem.user.name;
        shareItem.defaultContent = currentHotSpotsDetailsItem.hotSpotsDetailItem.user.name;
        shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_topic_describe" withValue:nil withTable:@"Language"];;
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = currentHotSpotsDetailsItem.hotSpotsDetailItem.share_url;
    }
    
   
    [CTShare shareItem:shareItem shareChannel:CTShareChannelWechatFriend publishType:CTPublishTypeNews shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
    
    
}
//分享到QQ空间
- (void)shareViewShareToQQSpace:(CTShareView *)view withImage:(UIImage *)image
{
    CTShareItem * shareItem;
    if (shareType == ShareTypeSubject) {
        CTSubjectItem * itm = [CTDataGenerator generateSubjectItems:currentHotSpotsItem];
        
        shareItem = [[CTShareItem alloc] init];
        shareItem.content = itm.describe;
        shareItem.defaultContent = itm.describe;
        shareItem.img = [UIImage imageNamed:@"60x3"];
        shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_topic_describe" withValue:nil withTable:@"Language"];;
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = itm.share_url;
    }else{
        shareItem = [[CTShareItem alloc] init];
        UIImage *img = shareImage;
        CGSize size = CGSizeMake(320, 320);
        shareItem.img = [CTImageProcessing imageCompressionImg:img WithSize:size];
        shareItem.content = currentHotSpotsDetailsItem.hotSpotsDetailItem.text;
        shareItem.defaultContent = currentHotSpotsDetailsItem.hotSpotsDetailItem.text;
        shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_pic_describe" withValue:nil withTable:@"Language"];;
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = currentHotSpotsDetailsItem.hotSpotsDetailItem.share_url;
    }
    
    
    [CTShare shareItem:shareItem shareChannel:CTShareChannelQQSpace publishType:CTPublishTypeImage shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}
//分享到新浪微博
- (void)shareViewShareToSina:(CTShareView *)view withImage:(UIImage *)image
{
    CTShareItem * shareItem;
    if (shareType == ShareTypeSubject) {
        CTSubjectItem * itm = [CTDataGenerator generateSubjectItems:currentHotSpotsItem];
        
        shareItem = [[CTShareItem alloc] init];
        shareItem.content = itm.share_url;
        shareItem.defaultContent = itm.describe;
        shareItem.img = [UIImage imageNamed:@"60x3"];
        shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_topic_describe" withValue:nil withTable:@"Language"];;
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = itm.share_url;
    }else{
        shareItem = [[CTShareItem alloc] init];
        shareItem.img = shareImage;
        shareItem.content = currentHotSpotsDetailsItem.hotSpotsDetailItem.share_url;
        shareItem.defaultContent = currentHotSpotsDetailsItem.hotSpotsDetailItem.share_url;
        shareItem.descr = [CTAppLanguage localizedStringForKey:@"share_pic_describe" withValue:nil withTable:@"Language"];;
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = currentHotSpotsDetailsItem.hotSpotsDetailItem.share_url;
    }
    [CTShare sinaBtnAction:shareItem shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });

    }];

}
//分享到微信
- (void)shareViewShareToWeChat:(CTShareView *)view withImage:(UIImage *)image
{
    CTShareItem * shareItem;
    if (shareType == ShareTypeSubject) {
        CTSubjectItem * itm = [CTDataGenerator generateSubjectItems:currentHotSpotsItem];
        
        shareItem = [[CTShareItem alloc] init];
        shareItem.content = [CTAppLanguage localizedStringForKey:@"share_topic_describe" withValue:nil withTable:@"Language"];
        shareItem.defaultContent = itm.describe;
        shareItem.img = [UIImage imageNamed:@"60x3"];
        shareItem.descr = itm.describe;
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = itm.share_url;
    }else{
        shareItem = [[CTShareItem alloc] init];
        shareItem.img = shareImage;//[CTRequestUtil requestImageWithUrl:currentHotSpotsDetailsItem.hotSpotsDetailItem.pic_url];
        shareItem.defaultContent = currentHotSpotsDetailsItem.hotSpotsDetailItem.text;
        shareItem.descr = currentHotSpotsDetailsItem.hotSpotsDetailItem.text;
        shareItem.content = [CTAppLanguage localizedStringForKey:@"share_pic_describe" withValue:nil withTable:@"Language"];
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = currentHotSpotsDetailsItem.hotSpotsDetailItem.share_url;
    }
    
    
    [CTShare shareItem:shareItem shareChannel:CTShareChannelWechat publishType:CTPublishTypeNews shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}
//分享到QQ
- (void)shareViewShareToQQ:(CTShareView *)view withImage:(UIImage *)image
{
    
    CTShareItem * shareItem;
    if (shareType == ShareTypeSubject) {
        CTSubjectItem * itm = [CTDataGenerator generateSubjectItems:currentHotSpotsItem];
        
        shareItem = [[CTShareItem alloc] init];
        shareItem.content = [CTAppLanguage localizedStringForKey:@"share_topic_describe" withValue:nil withTable:@"Language"];
        shareItem.defaultContent = itm.describe;
        shareItem.img = [UIImage imageNamed:@"60x3"];
        shareItem.descr = itm.describe;
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url = itm.share_url;
    }else{
        shareItem = [[CTShareItem alloc] init];
       
        UIImage *img = shareImage;//[CTRequestUtil requestImageWithUrl:currentHotSpotsDetailsItem.hotSpotsDetailItem.pic_url];
        CGSize size = CGSizeMake(320, 320);
        shareItem.img = [CTImageProcessing imageCompressionImg:img WithSize:size];
        shareItem.defaultContent = currentHotSpotsDetailsItem.hotSpotsDetailItem.text;
        shareItem.descr = currentHotSpotsDetailsItem.hotSpotsDetailItem.text;
        shareItem.content = [CTAppLanguage localizedStringForKey:@"share_pic_describe" withValue:nil withTable:@"Language"];
        shareItem.title = [CTAppLanguage localizedStringForKey:@"share_title" withValue:nil withTable:@"Language"];
        shareItem.url =  currentHotSpotsDetailsItem.hotSpotsDetailItem.share_url;
    }
    
    [CTShare shareItem:shareItem shareChannel:CTShareChannelQQ publishType:CTPublishTypeNews shareSuccessHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_successed" withValue:nil withTable:@"Language"]];
        });
    } shareFailedHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            CTRemindView * remindView = [[CTRemindView alloc] init];
            [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"remindView_Publish_failed" withValue:nil withTable:@"Language"]];
        });
    }];
}


#pragma mark - more view delegate -

- (void)moreViewDelBtnAction:(CTMoreView *)view
{
    reportType = ReportTypeDelete;
    
    NSString * titleStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Remind" withValue:nil withTable:@"Language"];
    NSString * messageStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Message_Delete" withValue:nil withTable:@"Language"];
    NSString * confirmStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Confirm" withValue:nil withTable:@"Language"];
    NSString * cancelStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Cancel" withValue:nil withTable:@"Language"];
    
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:titleStr message:messageStr delegate:self cancelButtonTitle:cancelStr otherButtonTitles:confirmStr, nil];
    [alertView show];
    
    view = nil;
}
- (void)moreViewreportBtnAction:(CTMoreView *)view
{
    reportType = ReportTypeReport;
    
    NSString * titleStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Remind" withValue:nil withTable:@"Language"];
    NSString * messageStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Message_Report" withValue:nil withTable:@"Language"];
    NSString * confirmStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Confirm" withValue:nil withTable:@"Language"];
    NSString * cancelStr = [CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Alert_Cancel" withValue:nil withTable:@"Language"];
    
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:titleStr message:messageStr delegate:self cancelButtonTitle:cancelStr otherButtonTitles:confirmStr, nil];
    [alertView show];
    
    view = nil;
}
- (void)moreViewCanacelBtnAction:(CTMoreView *)view
{

    view = nil;
}
- (void)moreViewDidRemoved:(CTMoreView *)view
{
    view = nil;
}

#pragma mark - alert view delegate -

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    if (buttonIndex == 1) {
        if (reportType == ReportTypeReport) {
            //举报
            acView = [[CTActivitorView alloc] init];
            [acView showActivitorViewOn:self.view withType:CTActivitorViewDefault];
            
            [logic reportRequest:[CTGenRequestData genRequestReportItem:currentHotSpotsDetailsItem.hotSpotsDetailItem.scheme_id] successCompletionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [acView removeActivitorView];
                    acView = nil;
                    
                    CTRemindView * remindView = [[CTRemindView alloc] init];
                    [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Report_Success" withValue:nil withTable:@"Language"]];
                    
                });
            } failedHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [acView removeActivitorView];
                    acView = nil;
                    
                    CTRemindView * remindView = [[CTRemindView alloc] init];
                    [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Report_Failed" withValue:nil withTable:@"Language"]];
                    
                });
            }];
        }else{
            //删除自己的发布内容
            
            acView = [[CTActivitorView alloc] init];
            [acView showActivitorViewOn:self.view withType:CTActivitorViewDefault];
       
            [logic deletePublishRequest:[CTGenRequestData genRequestDeletePublishItem:currentHotSpotsDetailsItem.hotSpotsDetailItem.scheme_id] successCompletionHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [[NSNotificationCenter defaultCenter] postNotificationName:CT_NOTI_DELETE_PUBLISH_SUCCESS object:nil];
                    
                    [acView removeActivitorView];
                    acView = nil;
                    
                    CTRemindView * remindView = [[CTRemindView alloc] init];
                    [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Delete_Success" withValue:nil withTable:@"Language"]];
                    
                });
            } failedHandler:^{
                dispatch_async(dispatch_get_main_queue(), ^{
                    
                    [acView removeActivitorView];
                    acView = nil;
                    
                    CTRemindView * remindView = [[CTRemindView alloc] init];
                    [remindView showRemindViewOn:self.view withRemindWord:[CTAppLanguage localizedStringForKey:@"CTHomePageViewController_Delete_Failed" withValue:nil withTable:@"Language"]];
                    
                });
            }];
            
        }
    }
    
    alertView.delegate = nil;
    [alertView removeFromSuperview];
    alertView = nil;
}


#pragma mark - login & exit -

-(void)visitorReLogin:(id)sender
{
    [self visitorLogin];
}

-(void)loginSuccess:(id)sender
{
    [self visitorLogin];
    
    //设置消息，取消当前用户与设备的绑定
    CTUserItem * userItem = [CTUser userInfo];
    [APService setAlias:userItem.uid callbackSelector:nil object:nil];
}
-(void)exitSuccess:(id)sender
{
    [self visitorLogin];
}

-(void)followPersonSuccess:(id)sender
{
   // [homePageView refresh];
    [self sendHotSpotDetailRequest];
    [self sendSubjectRequest];
}

-(void)cancelFollowPersonSuccess:(id)sender
{
    // [homePageView refresh];
    [self sendHotSpotDetailRequest];
    [self sendSubjectRequest];
}

-(void)likePersonSuccess:(id)sender
{
    // [homePageView refresh];
    [self sendHotSpotDetailRequest];
    [self sendSubjectRequest];
}

-(void)cancelLikePersonSuccess:(id)sender
{
    // [homePageView refresh];
    [self sendHotSpotDetailRequest];
    [self sendSubjectRequest];
}

-(void)publishCommentSuccessed:(id)sender
{
    // [homePageView refresh];
    [self sendHotSpotDetailRequest];
    [self sendSubjectRequest];
}

-(void)deleteCommentSuccessed:(id)sender
{
    // [homePageView refresh];
    [self sendHotSpotDetailRequest];
    [self sendSubjectRequest];
}

-(void)deletePublishSuccessed:(id)sender
{
    // [homePageView refresh];
    [self sendHotSpotDetailRequest];
    [self sendSubjectRequest];
}


-(void)publishSuccess:(id)sender
{
    [homePageView refresh];
}

-(void)clearCacheSuccess:(id)sender
{
    [homePageView refresh];
}


-(void)jumpToGroup:(id)sender
{
    NSNotification * noti = (NSNotification *)sender;
    CTTopic * topic = (CTTopic *)noti.object;
    
    [homePageView selectCurretGroup:topic];
    [homePageView refresh];
}

@end





